package com.highcom.coffeeshop.dao;

import org.springframework.stereotype.Repository;

import com.highcom.coffeeshop.model.Coffee;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Repository
public class CoffeeRepositoryImpl implements CoffeeRepository {

    private final List<Coffee> coffeeList = new ArrayList<>();

    public CoffeeRepositoryImpl() {
        // 初始化咖啡数据
        coffeeList.add(new Coffee(1, "元宇宙拿铁", 32.0, "虚拟与现实的完美融合，奶泡上会有你的数字分身"));
        coffeeList.add(new Coffee(2, "哈希焦糖玛奇朵", 36.0, "区块链技术加持，每口都是独一无二的哈希值"));
        coffeeList.add(new Coffee(3, "三进制冰美式", 28.0, "极简主义代表，只有0和1两种成分"));
        coffeeList.add(new Coffee(4, "递归卡布奇诺", 34.0, "无限自我调用的美味，每一口都唤起上一口的记忆"));
    }

    @Override
    public List<Coffee> findAll() {
        return new ArrayList<>(coffeeList);
    }

    @Override
    public Optional<Coffee> findById(int id) {
        return coffeeList.stream()
                .filter(coffee -> coffee.getId() == id)
                .findFirst();
    }
}